<template>
	<view>
		<view :class="{ isTop: isShow }" style="background-color: #f9f9f9">
			<baseHead :showReturn="false" :title="title" bg="#fff" @handleConfirm="handleConfirm" :showIcon="true"
				:lists="lists" :isClick="true" color="#000"
				:text_right="`批量操作${lenChecked == 0 ? '' : `(${lenChecked})`}`" @clickRight="clickRight" :right="true">
				<template slot="textnr">
					<view style="background-color: #ffffff; position: fixed; z-index: 999;width: 100%;">
						<u-search placeholder="搜索" v-model="KeyWord" @custom="handleSearch" @search="handleSearch"
							@clear="handleSearch" style="padding: 20rpx; background-color: #fff"></u-search>
						<u-tabs :list="list1" keyName="JobName" @click="clickTabs" lineHeight="0"
							:activeStyle="{ color: '#1684FC', fontSize: '26rpx' }"
							:inactiveStyle="{ color: '#333333', fontSize: '26rpx' }"
							style="background-color: #ffff; padding: 0 20rpx"></u-tabs>
					</view>
				</template>
			</baseHead>
			<!-- <u-sticky>
				<u-search placeholder="搜索" v-model="KeyWord" @custom="handleSearch" @search="handleSearch"
					@clear="handleSearch" style="padding: 20rpx; background-color: #fff"></u-search>
				<u-tabs :list="list1" keyName="JobName" @click="clickTabs" lineHeight="0"
					:activeStyle="{ color: '#1684FC', fontSize: '26rpx' }"
					:inactiveStyle="{ color: '#333333', fontSize: '26rpx' }"
					style="background-color: #ffff; padding: 0 20rpx"></u-tabs>
			</u-sticky> -->
			<scroll-view scroll-y class="scrollview" @scrolltolower="ReachBottom" @refresherrefresh="onrefresh"
				refresher-enabled='true' refresher-default-style='none' refresher-background='#f1f2f6'
				:refresher-threshold='15' :refresher-triggered='loading'
				:style="{'height':windowHeight-statusBarH-customBarH-safeAreaInsets-95+'px','margin-top':customBarH+'px'}">
				<u-loading-icon v-if="loading"></u-loading-icon>
				<view v-if="datalistdata.length > 0">
					<view class="jiaonliguanli" :class="{ active: isShow }" v-for="(item, index) in datalistdata" :key="index">
						<view class="check" v-if="isShow">
							<u-checkbox-group @change="handleChangeCheck(item,index)">
								<u-checkbox :checked="item.checked" size="21" shape="circle"></u-checkbox>
							</u-checkbox-group>
						</view>
						<view class="view-layout" @click="JobDetails(item,index)">
							<view class="view-left" v-if="item.Resume">
								<view class="avatar">
									<!-- <u-avatar class="avatar-img" :size="54" shape="square"
										:src="URL + item.Resume.BaseInfo.Avatar"></u-avatar> -->
									<image class="avatar-img" v-if="item.Resume.BaseInfo.Avatar"
										:src="URL + item.Resume.BaseInfo.Avatar"></image>
									<image class="avatar-img" v-else :src="item.Resume.BaseInfo.Sex == 1?man1:woman1"
										mode=""></image>
									<u--image class="avatar-sex"
										:src="item.Resume.BaseInfo.Sex == 1? '/static/image/my/man.png' : '/static/image/my/woman.png' "
										width="32rpx" height="32rpx"></u--image>
								</view>
								<view class="tips">
									<span v-if="item.Resume.BaseInfo.CurrentRole == 0">职场人</span>
									<span v-if="item.Resume.BaseInfo.CurrentRole == 1">学生</span>
								</view>
							</view>
							<view class="view-right">
								<view class="view-right-top">
									<view>
										<span class="name">{{ item.JobName || "XXXX" }}</span>
									</view>
									<view class="border-tips">
										<view class="tips-z" v-if="item.ApplyWayStr == '主动获取'">{{ item.ApplyWayStr }}
										</view>
										<view class="tips-q" v-else-if="item.ApplyWayStr == '求职者投递'">
											{{ item.ApplyWayStr }}
										</view>
									</view>
								</view>
								<view class="view-info" v-if="item.Resume">
									<span v-if="item.Resume.BaseInfo.Name">{{ item.Resume.BaseInfo.Name }}</span>
									<span v-if="item.Resume.BaseInfo.Age">{{ item.Resume.BaseInfo.Age + '岁' }}</span>
									<span
										v-if="item.Resume.BaseInfo.EducationLevelStr">{{ item.Resume.BaseInfo.EducationLevelStr }}</span>
									<span
										v-if="item.Resume.BaseInfo.WorkYear">{{ item.Resume.BaseInfo.WorkYear == -1 ? '在校生' : item.Resume.BaseInfo.WorkYear == 0 ?'应届生': item.Resume.BaseInfo.WorkYear+'年经验' }}</span>
									<span
										v-if="item.Resume.BaseInfo.CurrentStatusStr">{{ item.Resume.BaseInfo.CurrentStatusStr }}</span>
								</view>
								<view class="view-jieshao" v-if="item.Resume">
									<view v-if="item.Resume.GoodAtInfo.GoodAt">
										{{'自我介绍：' + item.Resume.GoodAtInfo.GoodAt }}
									</view>
								</view>
							</view>
						</view>
					</view>
					<u-loadmore :status="status" />
				</view>
				<u-empty v-else mode="data" icon="/static/recruit/index/qsy.png" width="350" marginTop="150">
				</u-empty>
			</scroll-view>

			<view class="fiexd" v-if="isShow">
				<u-grid :show-border="false" @click="click" style="justify-content: center;">
					<u-grid-item v-show="this.obj.CollectionType == 0 || this.obj.CollectionType !== 1">
						<text class="grid-text">移入简历暂存夹</text>
					</u-grid-item>
					<u-grid-item v-show="this.obj.CollectionType == 0 || this.obj.CollectionType !== 2">
						<text class="grid-text">移入人才储备库</text>
					</u-grid-item>
					<u-grid-item v-show="this.obj.CollectionType == 0 || this.obj.CollectionType !== 3">
						<text class="grid-text">移入简历回收站</text>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
	</view>
</template>
<script>
	import baseHead from "@/pages/component/baseHead.vue";
	export default {
		filters: {
			userNums(num) {
				return num < 10000 ? num : (num / 1000).toFixed(1) + "k";
			}
		},
		data() {
			return {
				statusBarH: 0, //状态栏高度
				customBarH: 0, //导航栏高度
				windowWidth: 0, //窗口宽度
				windowHeight: 0, //窗口高度
				safeAreaInsets: 0, //底部导航栏
				URL: this.$config.domain.staticUrl,
				checked: "",
				KeyWord: "",
				datalist: [],
				list1: [],
				obj: {
					KeyWord: "",
					JobId: "",
					CollectionType: 0,
					PageIndex: 1,
					PageSize: 10,
					State: [0, 1] //反馈状态
				},
				status: "loadmore",
				title: "简历收件箱",
				lists: [],
				lenChecked: 0,
				isShow: false,
				listObj: {
					label: "简历收件箱",
					id: 0,
				},
				loading: false,
				man1: "/static/recruit/index/nan.png",
				woman1: "/static/recruit/index/nv.png",
			};
		},
		props: {
			showIcon: {
				type: Boolean,
				default: false,
			},
			isClick: {
				type: Boolean,
				default: false,
			},
		},
		//子组件
		components: {
			baseHead,
		},
		created() {
			const app = getApp()
			// 获取状态栏和导航条高度 窗口宽度
			this.statusBarH = app.globalData.statusBarH;
			this.customBarH = app.globalData.customBarH;
			this.windowWidth = app.globalData.phoneInformation.windowWidth;
			this.windowHeight = app.globalData.phoneInformation.windowHeight;
			this.safeAreaInsets = app.globalData.phoneInformation.safeAreaInsets.bottom;
			this.initList();
			this.initTab();
			this.listdata();
		},
		// 下拉刷新
		// onPullDownRefresh() {
		// 	this.obj = {
		// 		KeyWord: "",
		// 		JobId: "",
		// 		PageIndex: 1,
		// 		PageSize: 10,
		// 	};
		// 	this.listdata();
		// 	uni.stopPullDownRefresh(); //停止刷新
		// },
		// 计算属性
		computed: {
			datalistdata() {
				return this.datalist
			}
		},
		// 计算方法
		methods: {

			onrefresh() {
				this.loading = true;
				setTimeout(() => {
					this.loading = false;
					this.datalist = [];
					this.obj = {
						KeyWord: "",
						JobId: "",
						PageIndex: 1,
						PageSize: 10,
					};
					this.listdata();
				}, 1000);
			},

			ReachBottom() {
				console.log("懒加载");
				// 加载前值为loadmore，加载中为loading，没有数据为nomore
				if (this.status != "nomore") {
					this.status = "loading";
					this.listdata();
				}
			},
			numberFormat(num, val) {
				let newNum = num / 1000;
				newNum = newNum.toString();
				const index = newNum.indexOf(".");
				if (index !== -1) {
					if (!val) {
						return parseFloat(newNum).toFixed(1) + "k";
					} else {
						return parseFloat(newNum).toFixed(1);
					}
				} else {
					if (!val) {
						return parseFloat(newNum) + "k";
					} else {
						return parseFloat(newNum);
					}
				}
			},
			tofixed1(num) {
				num = num.toString();
				const index = num.indexOf(".");
				if (index !== -1) {
					num = num.substring(0, index + 2);
					return parseFloat(num).toFixed(1);
				} else {
					num = num.substring(0);
					return parseFloat(num);
				}
			},
			handleConfirm(val) {
				console.log(val);
				this.title = val.label;
				if (val.id == 0) {
					this.obj.State = [0, 1]
				} else if (val.id == 1 || val.id == 2) {
					this.obj.State = [2]
				} else {
					this.obj.State = [4]
				}
				this.lenChecked = 0;
				this.obj.CollectionType = val.id;
				this.isShow = false;


				if (this.isShow) {
					uni.hideTabBar();
				} else {
					uni.showTabBar();
				}

				this.status = "loadmore";
				this.obj.PageIndex = 1;
				this.datalist = [];
				this.listdata();
			},
			click(name) {
				let arr = [];
				let checkedList = this.datalist.filter((item) => {
					return item.checked == true;
				});
				if (checkedList.length == 0) {
					return;
				}
				checkedList.forEach((item) => {
					arr.push(item.Id);
				});
				let obj = {
					Id: arr,
					CollectionType: name + 1,
				};
				this.$http.huirc.inboxuptype(obj).then((res) => {

					this.obj = {
						...this.obj,
						PageIndex: 1,
						PageSize: 10,
					};
					this.datalist = [];
					this.lenChecked = 0;
					this.status = "loadmore";
					this.listdata();
					this.$util.toast(res.Message);
					this.isShow = false
				});
			},
			JobDetails(item, index) {
				console.log(item);
				console.log(this.obj);
				// if(!this.obj.JobId){
				// 	this.obj.JobId=item.JobExpectId
				// }
				let int = item.ResumeId;
				if (this.isShow) {
					this.datalist[index].checked = !this.datalist[index].checked;
					console.log(this.datalist);
				} else {
					uni.navigateTo({
						url: `/pages/views/packageA/type-recruit/search/JobDetails?key=${int}&id=${item.JobExpectId}&distinguish=true&jobId=${item.JobId}`,
					});
				}
			},
			handleChangeCheck(item, index) {
				console.log(item, index);
				this.datalist[index].checked = !this.datalist[index].checked;
			},
			clickRight() {
				this.isShow = !this.isShow;
				if (!this.isShow) {
					this.lenChecked = 0;
					this.datalist = this.datalist.map((item) => {
						return {
							...item,
							checked: false,
						};
					});
				}
				if (this.isShow) {
					uni.hideTabBar();
				} else {
					uni.showTabBar();
				}
			},
			initList() {
				this.$http.huirc.inboxcollection().then((res) => {
					if (res.Result) {
						this.lists = res.Result.map((item) => {
							return {
								label: item.Item1,
								id: item.Item2,
							};
						});
						this.lists.unshift({
							label: "简历收件箱",
							id: 0,
						});
						this.lists = [this.lists];
						console.log(this.lists);
					}
				});
			},
			handleSearch(val) {

				console.log(val, 'dddd')

				this.obj.KeyWord = val;
				this.obj.PageIndex = 1;
				this.obj.JobId = "";
				this.datalist = [];
				this.listdata();
			},
			initTab() {
				this.$http.huirc.inboxjob().then((res) => {
					if (res.Result) {
						// console.log(res)
						this.list1 = res.Result;
						this.list1.unshift({
							JobId: "",
							JobName: "全部",
						});
					}
				});
			},
			listdata(val) {
				this.$http.huirc.inboxlist(this.obj).then((res) => {
					if (res.Result) {
						// console.log(uni.getStorageSync('dianjiqiye'))
						if (this.obj.PageIndex == 1 && res.Result.Items.length == 0) {
						this.datalist = [];
						} else {
						if (res.Result.Items.length == 0) {
							// 没有数据----
							this.status = "nomore";
							return;
						}
						let arr = res.Result.Items.map((item) => {
							return {
								...item,
								checked: false,
							}
						})
						this.datalist = this.datalist.concat(arr)
						}
						console.log(res.Result.Items.length,'---------------------')
						if (res.Result.Items.length >= this.obj.PageSize) {
							this.obj.PageIndex++;
							this.status = "loadmore";
							// 表示还有数据
						} else {
							console.log("没有更多数据了");
							//没有更多数据了
							this.status = "nomore";
						}
					}
				})
			},
			clickTabs(item) {
				console.log("item", item);

				this.KeyWord = "";

				this.obj.JobId = item.JobId;
				this.obj = {
					...this.obj,

					KeyWord: "",

					JobId: this.obj.JobId || "",
					PageIndex: 1

				};
				this.datalist = [];
				this.status = "loadmore";
				this.listdata();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scrollview {

		box-sizing: border-box;
		padding: 0rpx 20rpx;
	}

	.isTop {
		padding-bottom: 100rpx;
	}

	.jiaonliguanli {
		background-color: #ffffff;
		// padding: 0 40rpx;
		padding-left: 20rpx;
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;

		&.active {
			background-color: #f9f9f9;
			width: 105%;

			.view-layout {
				background-color: #ffffff;
				padding: 20rpx;
			}
		}

		.check {
			display: flex;
			margin-right: 15rpx;
		}

		.view-layout {
			flex: 1;
			display: flex;
			justify-content: space-between;
			padding: 20rpx 0;
		}

		.view-right {
			margin-left: 25rpx;
			flex: 1;
			display: flex;
			flex-direction: column;
			align-content: space-between;
			justify-content: space-between;
			margin-bottom: 8rpx;

			.view-right-top {
				width: 100%;
				display: flex;
				justify-content: space-between;
				border-radius: 4rpx;
				position: relative;

				.name {
					font-size: 32rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #000000;
				}

				.money {
					margin-left: 20rpx;
					font-size: 30rpx;
					font-weight: 500;
					color: #f35370;
				}

				.border-tips {
					padding-right: 20rpx;
					position: absolute;
					top: -30rpx;
					right: 0rpx;
					height: 36rpx;

					.tips-z {
						width: 100%;
						height: 100%;
						font-size: 24rpx;
						white-space: nowrap;
						color: #fff;
						display: flex;
						align-items: center;
						padding-left: 38rpx;
						background-image: url("/static/recruit/index/zdhq.png");
						background-size: 100% 100%;
					}

					.tips-q {
						width: 100%;
						height: 100%;
						font-size: 24rpx;
						white-space: nowrap;
						color: #fff;
						display: flex;
						align-items: center;
						padding-left: 38rpx;
						background-size: 100% 100%;
						background-image: url("/static/recruit/index/qzztd.png");
					}
				}
			}

			.view-info {
				margin-top: 25rpx;

				span {
					font-size: 24rpx;
					color: #313131;
					padding: 0 12rpx;
					border-right: 1rpx solid #313131;
					line-height: 24rpx;

					&:first-child {
						padding-left: 0;
					}

					&:last-child {
						border-right: 0;
					}
				}
			}

			.view-jieshao {
				margin-top: 25rpx;
				color: #000000;
				font-size: 24rpx;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				line-clamp: 2;
				-webkit-box-orient: vertical;
			}
		}

		.viewtext {
			padding: 10rpx 0rpx;
		}

		.textmianst {
			border: 1px solid #e9e9e9;
			margin-left: 40rpx;
			font-size: 20rpx;
			padding: 5rpx 20rpx;
		}

		.potstycp {
			position: absolute;
			top: 20rpx;
			right: 40rpx;
		}

		.potstpth {
			position: absolute;
			bottom: 20rpx;
			background-color: #f1f2f6;
			right: 40rpx;
			padding: 10rpx 20rpx;
			border-radius: 10rpx;
		}
	}

	.avatar {
		position: relative;
		display: flex;
		width: 108rpx;
		height: 108rpx;

		.avatar-img {
			width: 108rpx;
			height: 108rpx;
			position: absolute;
			border-radius: 4px;
		}

		.avatar-sex {
			position: absolute;
			right: 0;
			bottom: 0;

			span {
				background-color: #fff;
				color: #fff;
			}
		}
	}

	.tips {
		margin-top: 30rpx;
		border: 1px solid #e9e9e9;
		border-radius: 4rpx;
		padding: 5rpx 10rpx;
		font-size: 24rpx;
		text-align: center;
		color: #666666;
	}

	.fiexd {
		position: fixed;
		bottom: 0;
		width: 100%;
		background-color: #fff;
		box-shadow: 0px 0px 5px 1px rgba(131, 140, 149, 0.14);

		.grid-text {
			font-size: 28rpx;
			line-height: 98rpx;
		}
	}
</style>